//! @file   lc_base.h
//! @brief  
//! @author Sayan Chaliha
//! @date   September, 2011
//!
//! 
#ifndef _LC_BASE_H
#define _LC_BASE_H

#include "libcyan_internal.h"
#include "lc_types.h"
#include "lc_system.h"
#include "lc_char_traits.h"

namespace cyan {
    class CYAN_API Object {
    public:
        static const UInt32 hashSeed = 5381U;
        Object() {
        }
        
        virtual ~Object() {
        }
        
        virtual UInt32 hashCode() const {
            return -1;
        }
        
        template <typename T>
        Bool instanceOf() const {
            return Object::instanceOfHelper_<T>(this);
        }
        
        template <typename T>
        Bool instanceOf(const T&) const {
            return Object::instanceOfHelper_<T>(this);
        }
        
    protected:
        template <typename A, typename B>
        static Bool instanceOfHelper_(const B* const pointer) {
            typedef typename RemoveConstVolatile<A>::Type TypeA;
            typedef typename RemoveConstVolatile<B>::Type TypeB;
            
            try {
                if (AreSame<TypeA, TypeB>::value)
                    return true;
                
                TypeA* a = dynamic_cast<TypeA*> (const_cast<TypeB*> (pointer));
                
                if (a)
                    return true;
                else
                    return false;
            } catch (...) {
                return false;
            }
        }
    };
}
#endif /* _LC_BASE_H */
